<template>
	<view>
		<view class="item" v-for="item in dataList" @click="goDetail(item)">
			<div class="circle"></div>
			<div class="content">
				<div class="one">订单号:{{ item.sorderNo }},报工数: {{ item.iqty }}</div>
				<div class="two">日期: {{ item.doutputDate }}</div>
				<div class="three">
					{{ item.sprocedureName }}
					颜色：{{ item.scolorName }}
					尺码：{{ item.ssizeName }}
				</div>
			</div>
		</view>
		<u-loadmore :status="status"  @loadmore="loadmore" :line="true" />
		<uni-fab
			@fabClick="trigger()"
		></uni-fab>
	</view>
</template>

<script>
	import rfidOutput from "@/api/fuzhuang/rfidOutput"
	export default {
		data() {
			return {
				status: 'loadmore',
				dataList: [],
				tablePage: {
					pages: 0,
					currentPage: 0,
					pageSize: 10
				},
			}
		},
		onShow() {
			uni.showLoading({
				title: '加载中'
			});
			uni.$off('refreshData');
			uni.$on('refreshData',() => {
				this.loadAgain();
			});
			setTimeout(() => {
				uni.hideLoading();
			}, 1000);
		},
		onLoad() {
			this.loadmore();
		},
		methods: {
			onReachBottom() {
				this.loadmore();
			},
			// 点击跳转详情页面
			goDetail(item) {
				uni.navigateTo({
					url: `/pages/fuzhuang/reportWork/detail?sbillNo=${item.sbillNo}`
				});
			},
			loadmore() {
				if(this.tablePage.currentPage!==0 &&
					 this.tablePage.pages <=
					 this.tablePage.currentPage) {
					this.status = 'nomore';
					return;
				}
				this.tablePage.currentPage = ++ this.tablePage.currentPage;
				//联网加载数据
				this.status = 'loading';
				uni.showLoading({
					title: '加载中'
				});
				rfidOutput.queryOutputDataList({
					current: this.tablePage.currentPage,
					size: this.tablePage.pageSize,
					orders: [{ column: "t.create_time", asc: false }]
				}).then(data => {
					//追加新数据
					this.dataList = this.dataList.concat(data.records);
					this.tablePage = {
						pages: data.pages,
						currentPage: data.current,
						pageSize: data.size
					};
					if(this.tablePage.pages <= this.tablePage.currentPage){
						this.status = 'nomore';
					} else {
						this.status = 'loadmore';
					}
					uni.hideLoading();
				}).catch(error => {
					uni.hideLoading();
				})
			},
			loadAgain() {
				rfidOutput.queryOutputDataList({
					current: 1,
					size: 10,
					orders: [{ column: "t.create_time", asc: false }]
				}).then(data => {
					this.dataList = data.records;
					this.tablePage = {
						pages: data.pages,
						currentPage: data.current,
						pageSize: data.size
					};
					if(this.tablePage.pages <= this.tablePage.currentPage){
						this.status = 'nomore';
					} else {
						this.status = 'loadmore';
					}
					uni.hideLoading();
				}).catch(error => {
					uni.hideLoading();
				})
			},
			trigger() {
				uni.navigateTo({
					url: '/pages/fuzhuang/reportWork/detail'
				});
			}
		}
	}
</script>

<style scoped>
.item {
	padding: 0 10px;
	display: flex;
	height: 70px;
	align-items: center;
	margin-top: 10px;
	width: 100%;
}
.circle {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background-color: navajowhite;
}
.content {
	display: flex;
	flex-direction: column;
	padding-left: 10px;
}
.one {
	font-weight: bold;
	font-size: 16px
}
.two {
	font-size: 14px;
}
.three {
	color: #999;
}
</style>
